<script setup lang="ts">
import router from '@/router';
import { useUserStore } from '@/stores/user';
import { ElMessageBox } from 'element-plus'


const useStore = useUserStore();
const handleCommand = (command: string) => {
  if (command === 'layout') {

    //实现提示
    ElMessageBox.confirm('确定要退出登录吗？', '退出登录', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
    }).then(() => {
      // 1.清除Token
      useStore.removeToken()
      // 2.跳转到登录页面
      // router.replace('/login')
      router.push('/login')
    })
      .catch(() => { })
  }
}
</script>

<template>
  <div class="nav-bar">
    <!-- breadcrumb -->
    <div></div>
    <!-- dropdown -->
    <el-dropdown @command="handleCommand">
      <div class="user-wrapper">黑马管理员</div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item command="index">首页</el-dropdown-item>
          <el-dropdown-item command="project">项目地址</el-dropdown-item>
          <el-dropdown-item command="layout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<style lang="scss" scoped>
.nav-bar {
  height: 60px;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;

  .user-wrapper {
    outline: none;
    cursor: default;
    color: var(--el-color-black);
  }
}
</style>
